//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet
{
    class CellEvaluationContext : WorksheetLevelEvaluationContext
    {
        private readonly Cell _target;
        private readonly CellRelativeAddress _offset;

        public CellEvaluationContext(Cell target)
        {
            Contract.Requires(target != null);
            _target = target;
        }
       
        private CellEvaluationContext(Cell target, CellRelativeAddress offset): this (target)
        {
            _offset = offset;
        }

        public override Cell Target
        {
            get { return _target; }
        }

        public override CellRelativeAddress Offset
        {
            get { return _offset; }
        }

        public override Worksheet Worksheet
        {
            get
            {
                return Target.Worksheet;
            }
        }


        public bool IsArray
        {
            get; set;
        }

        internal override EvaluationContext CreateOffseted(CellRelativeAddress cellRelativeAddress)
        {
            return new CellEvaluationContext(Target, Offset + cellRelativeAddress) {IsArray = IsArray};
        }
    }
}